<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>渐变色-基本使用</title>
    <style>
      body,
      ul {
        margin: 0;
        padding: 0;
      }

      body {
        background-image: url(../../images/grid.png);
      }
      svg {
        background-color: rgba(255, 0, 0, 0.1);
      }
    </style>
  </head>
  <body>
    <svg width="300" height="300" xmlns="http://www.w3.org/2000/svg">
      <!-- 定义可以复用的元素: 样式, 渐变, 图形, 滤镜... -->
      <defs>
        <!-- 默认的渐变色 -->
        <linearGradient id="gradient1">
          <stop offset="0%" stop-color="red"></stop>
          <stop offset="50%" stop-color="green"></stop>
          <stop offset="100%" stop-color="blue"></stop>
        </linearGradient>

        <!-- 制定渐变的方向 -->
        <linearGradient id="gradient2" x1="0%" y1="0%" x2="100%" y2="0%">
          <stop offset="0%" stop-color="red"></stop>
          <stop offset="50%" stop-color="green"></stop>
          <stop offset="100%" stop-color="blue"></stop>
        </linearGradient>

        <!-- 制定渐变的形状 -->
        <linearGradient id="gradient3" x1="0%" y1="0%" x2="0%" y2="100%">
          <stop offset="0%" stop-color="red"></stop>
          <stop offset="50%" stop-color="green"></stop>
          <stop offset="100%" stop-color="blue"></stop>
        </linearGradient>

        <!-- 制定渐变的形状 -->
        <linearGradient id="gradient4" x1="0%" y1="0%" x2="100%" y2="100%">
          <stop offset="0%" stop-color="red"></stop>
          <stop offset="50%" stop-color="green"></stop>
          <stop offset="100%" stop-color="blue"></stop>
        </linearGradient>
      </defs>

      <!-- 使用渐变填充 -->
      <rect
        x="10"
        y="10"
        width="200"
        height="200"
        fill="url(#gradient1)"
      ></rect>
      <rect
        x="10"
        y="220"
        width="200"
        height="200"
        fill="url(#gradient2)"
      ></rect>
      <rect
        x="220"
        y="10"
        width="200"
        height="200"
        fill="url(#gradient3)"
      ></rect>
      <rect
        x="220"
        y="220"
        width="200"
        height="200"
        fill="url(#gradient4)"
      ></rect>
    </svg>
  </body>
</html>
